<template>
    <div style="height:100%;width:100%;position:relative;" ref="maindev">
        <div class="pagetop" :style="{ height:'130px' }">
            <table style="width: 100%; font-size: 12px;" border="0">
                <col style="width: 4%;" />
                <col style="width: 8%;" />
                <col style="width: 1%;" />
                <col style="width: 8%;" />
                <col style="width: 4%;" />
                <col style="width: 11%;" />
                <col style="width: 5%;" />
                <col style="width: 11%;" />
                <col style="width: 5%;" />
                <col style="width: 11%;" />
                <col style="width: 4%;" />
                <col style="width: 11%;" />
                <col style="width: 43%;" />
                <tr>
                    <td align="right">报告日期</td>
                    <td>
                        <el-date-picker v-model="searchObj.sample_startdt" :able="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" :clearable="false" @change="ClearData"></el-date-picker>
                    </td>
                    <td>至</td>
                    <td>
                        <el-date-picker v-model="searchObj.sample_enddt" type="date" :able="false" placeholder="选择日期" :default-time="['23:59:59']" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" :clearable="false" @change="ClearData"> </el-date-picker>
                    </td>
                    <td align="right">病历号</td>
                    <td>
                        <el-input size="small" style="width:100%;min-width:130px" v-model="searchObj.pat_no" clearable @focus="Focus($event)" @change="ClearData"></el-input>
                    </td>

                    <td>条码号</td>
                    <td>
                        <el-input size="small" style="width:100%;" v-model="searchObj.barcode" @focus="Focus($event)" @change="ClearData"></el-input>
                    </td>
                    <td align="right">报告项目</td>
                    <td>
                        <rm-ddl-rptitem prgno="LIS422" isAllRpt="1" v-model="searchObj.rpt_itemcode" width="100%" :appendtobody="true" @change="ClearData"></rm-ddl-rptitem>
                    </td>
                    <td align="right">标本类型</td>
                    <td>
                        <rm-ddl-common ref="ddlspecimen" datatype="specimen" dataname="标本类型" v-model="searchObj.specimen_code" width="100%" @change="ClearData"></rm-ddl-common>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="color:RoyalBlue;font-weight:600">病人类型</td>
                    <td colspan="3">
                        <el-select v-model="searchObj.pat_typecode" @dblclick.native="popMultipleChk(searchObj.pat_typecode,'searchObj.pat_typecode',pattypeOption,'病人类型选择')" filterable clearable style="width:100%" @change="ChangeNSaveChache">
                            <el-option v-for="(item,index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                        </el-select>
                    </td>
                    <td align="right">姓名</td>
                    <td>
                        <el-input size="small" style="width:calc( 100% - 60px );" v-model="searchObj.pat_name" @focus="Focus($event)" @change="ClearData"></el-input> &nbsp;
                        <el-checkbox v-model="searchObj.pat_name_mh" @change="ClearData">模糊</el-checkbox>
                    </td>

                    <td align="right">检验组别</td>
                    <td>
                        <!-- @dblclick.native="popMultipleChk(searchObj.labgroup,'searchObj.labgroup',labgroupOption,'请选择检验组别')" -->
                        <el-select v-model="searchObj.labgroup" filterable clearable style="width:100%" @change="ClearData">
                            <el-option v-for="(item,index) in labgroupOption" :key="index" :value="item.data" :label="item.display"></el-option>
                        </el-select>
                    </td>
                    <td align="right">单元组合</td>
                    <td>
                        <!-- @dblclick.native="popMultipleChk(searchObj.rptunitgroupid,'searchObj.rptunitgroupid',rptunitGroupOption,'单元组合选择')"  -->
                        <el-select v-model="searchObj.rptunitgroupid" style="width:100%" filterable clearable @change="ClearData">
                            <el-option v-for="(item,index) in rptunitGroupOption" :key="index" :value="item.data" :label="item.display">
                            </el-option>
                        </el-select>
                    </td>
                    <td align="right">检验者</td>
                    <td>
                        <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchObj.report_user" width="100%" @change="ClearData"></rm-ddl-common>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="color:RoyalBlue;font-weight:600">检验科室</td>
                    <td colspan="3">
                        <el-select v-model="searchObj.labdeptcode" @dblclick.native="popMultipleChk(searchObj.labdeptcode,'searchObj.labdeptcode',labdeptOption,'检验科室选择')" filterable clearable style="width:100%" @change="ChangeNSaveChache">
                            <el-option v-for="(item,index) in labdeptOption" :key="index" :value="item.data" :label="item.display">
                            </el-option>
                        </el-select>
                    </td>
                    <td align="right" style="color:	RoyalBlue;font-weight:600">打印状态</td>
                    <td>
                        <el-select v-model="searchObj.isprint" placeholder="请选择" style="width:100%" @change="ChangeNSaveChache">
                            <el-option key="0" label="未打印" value="0"></el-option>
                            <el-option key="1" label="已打印" value="1"></el-option>
                            <el-option key="all" label="全部" value="all"></el-option>
                        </el-select>
                    </td>
                    <td align="right" style="color:	RoyalBlue;font-weight:600">科室/病区</td>
                    <td>
                        <el-select v-model="searchObj.chkmode" placeholder="请选择" style="width:100%" @change="ChangeNSaveChache">
                            <el-option key="0" label="病区模式" value="0"></el-option>
                            <el-option key="1" label="科室模式" value="1"></el-option>
                        </el-select>
                    </td>
                    <td align="right">病区组合</td>
                    <td>
                        <rm-ddl-common :appendtobody="true" datatype="wardcomb" dataname="病区" v-model="searchObj.wdcombno" width="100%" @change="ClearData"></rm-ddl-common>
                    </td>
                    <td align="right">审核者</td>
                    <td>
                        <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchObj.rechk_user" width="100%" @change="ClearData"></rm-ddl-common>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" align="left" style="align:left;text-align:left;width:100%;font-size:16px;font-weight:600">
                        <el-tag style="margin:1.3px 3px;height:22px;font-size:13px;line-height:22px">选中一行，再按住Shift点击另一行，可快速勾选其间所有报告。</el-tag>
                    </td>
                    <td colspan="7" align="right" style="text-align:right;width:100%">
                        <el-button icon="el-icon-search" v-has="'PINQUERY'" type="primary" @click="BtnQuery">查询(F8)</el-button>
                        <el-button icon="el-icon-delete" @click="BtnClear">清除(C)</el-button>
                        <el-button v-has="'PPRINT'" @click.native="BtnPreView" icon="el-icon-zoom-in">预览</el-button>
                        <el-button v-has="'PPRINT'" @click.native="BtnPrint" icon="el-icon-printer">打印</el-button>
                        <el-button v-has="'PVIEWCASE'" icon="el-icon-notebook-2" @click="BtnQueryPatcase">查阅病历</el-button>
                        <el-button icon="el-icon-close" @click="BtnExc" type="warning">退出(E)</el-button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pagecenter">
            <div class="middle_center">
                <el-tabs v-model="activeTabName" @tab-click="HandleClick" style="height:100%;" type="border-card" ref="tabs">
                    <el-tab-pane label="报告单" name="rptTab">
                        <rm-layout-right splitcolor="#ffffff" :splitwidth="5" :fixsize="450" :minfixsize="200" :maxfixsize="850">
                            <rm-layout-left splitcolor="#ffffff" :splitwidth="5" :fixsize="180" :minfixsize="100" :maxfixsize="300">
                                <template v-slot:fix>
                                    <vxe-table :data.sync="listData" :loading="bListLoading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="listTable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" header-align="center" :key="listKey" @current-change="listCurrentChange" :row-class-name="rptRowName">
                                        <!-- <vxe-table-column type="index" align="center" title="序号" width="40"></vxe-table-column> -->
                                        <vxe-table-column v-if="searchObj.chkmode=='0'?true:false" field="req_ward" sortable title="病区列表" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column v-if="searchObj.chkmode=='0'?false:true" field="req_dept" sortable title="科室列表" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="cnt" align="center" sortable title="份数" width="50" show-overflow></vxe-table-column>
                                    </vxe-table>
                                </template>
                                <vxe-table :data.sync="rptData" :loading="bRptLoading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="rptTable" resizable show-overflow size="mini" :row-class-name="rptRowName" show-header-overflow :optimization="{animat: false}" @current-change="rptCurrentChange" :cell-class-name="rptCellName" header-align="center" :key="rptkey">
                                    <vxe-table-column field="req_bedno" align="center" sortable title="床号" width="50" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_name" align="center" sortable title="病人姓名" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_no" sortable title="病人号" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_sexname" align="center" sortable title="性别" width="35" show-overflow></vxe-table-column>
                                    <vxe-table-column field="specimen" sortable title="标本类型" width="90" show-overflow></vxe-table-column>
                                    <vxe-table-column align="center" field="sampledate" sortable title="标本日期" width="70" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
                                    <!--  添加打印选择-->
                                    <vxe-table-column field="cp_selection" title="选择" width="40px" align="center" sortable>
                                        <template v-slot:header="{ column }">
                                            <el-checkbox v-model="selectall" @change="ChkAll($event)"></el-checkbox>
                                        </template>
                                        <template v-slot="{ row, rowIndex }">
                                            <el-checkbox v-model="row.cp_selection" true-label="1" false-label="0" @change="handleCheckedPrintChange(row, rowIndex)"></el-checkbox>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="rptunitname" sortable title="报告单元" width="130" show-overflow></vxe-table-column>
                                    <vxe-table-column field="report_dt" align="center" sortable title="报告时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="req_dept" sortable title="申请科室" width="150" show-overflow></vxe-table-column>
                                    <vxe-table-column field="req_doc" align="center" sortable title="申请医生" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="req_dt" align="center" sortable title="申请时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="recieve_dt" align="center" sortable title="接收时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_sexname" align="center" sortable title="性别" width="50" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_agestr" align="center" sortable title="年龄" width="40" show-overflow></vxe-table-column>
                                    <vxe-table-column field="pat_typecodename" align="center" sortable title="病人类别" width="80" show-overflow></vxe-table-column>
                                    <vxe-table-column field="alter_flag" sortable title="危" width="20" show-overflow align="center">
                                        <template v-slot="{ row, rowIndex, columnIndex }">
                                            <div :key="row.userno+rowIndex+columnIndex" v-if="row.alter_flag == '1'||row.alter_flag=='2'">
                                                <font color="#000000">危</font>
                                            </div>
                                            <div :key="row.userno+rowIndex+columnIndex" v-else>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="emer_flag" sortable title="急" width="20" show-overflow align="center">
                                        <template v-slot="{ row, rowIndex, columnIndex }">
                                            <div :key="row.userno+rowIndex+columnIndex" v-if="row.emer_flag == '1'">
                                                <font color="red">急</font>
                                            </div>
                                            <div :key="row.userno+rowIndex+columnIndex" v-else>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="redo_flag" sortable title="复" width="20" show-overflow align="center">
                                        <template v-slot="{ row, rowIndex, columnIndex }">
                                            <div :key="row.userno+rowIndex+columnIndex" v-if="row.redo_flag =='2' || row.redo_flag=='3'">
                                                <font color="#000000">复</font>
                                            </div>
                                            <div :key="row.userno+rowIndex+columnIndex" v-else>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="barcode" sortable title="条码号" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="req_ward" sortable title="病人病区" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="sampleno" align="center" sortable title="标本号" width="60" show-overflow :sort-width="20"></vxe-table-column>
                                    <vxe-table-column field="pat_diag" sortable title="临床诊断" width="250" show-overflow></vxe-table-column>
                                    <vxe-table-column field="sampled_dt" align="center" sortable title="采样时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="input_dt" align="center" sortable title="录入时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="test_info" sortable title="上机信息" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="test_dt" align="center" sortable title="上机时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="report_username" align="center" sortable title="检验医生" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rechk_dt" align="center" sortable title="审核时间" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rechk_user" align="center" sortable title="审核医生" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="item_num" align="center" sortable title="项目数" width="50" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rechk2_dt" align="center" sortable title="二审时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rechk2_user" align="center" sortable title="二审医生" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="lastprint_dt" align="center" sortable title="最后打印时间" width="140" show-overflow></vxe-table-column>
                                    <vxe-table-column field="print_count" align="center" sortable title="打印次数" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="reportid" sortable title="报告ID" width="160" show-overflow></vxe-table-column>
                                    <vxe-table-column field="report_comm" sortable title="报告单备注" width="150" show-overflow></vxe-table-column>
                                    <vxe-table-column field="unprint_flag" align="center" sortable title="禁止打印标志" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="unprint_reason" sortable title="禁止打印原因" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="req_reason" sortable title="送检目的" width="400" show-overflow></vxe-table-column>
                                    <vxe-table-column field="exprint_count" align="center" sortable title="外部打印次数" width="90" show-overflow></vxe-table-column>
                                    <template v-slot:fix>
                                        <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">合计: {{rpt_amount}}</span>
                                            <div style="clear:both"></div>
                                        </div>
                                    </template>
                                </vxe-table>
                            </rm-layout-left>
                            <template v-slot:fix>
                                <div v-if="bIsYm" class="right-inser">
                                    <div class="middle-tab-top">
                                        <vxe-table :data.sync="resultData" :loading="bResultLoading" header-align="center" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="200px" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" :key="ymitemkey">
                                            <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="220" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result_str" sortable title="检测结果" width="80" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result1" sortable title="菌落计数" width="150" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result4" sortable title="耐药机制" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="instrna" sortable title="检验仪器" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="interno" sortable title="通道号" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="alertflag" align="center" sortable title="危急标志" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result_flag" align="center" sortable title="结果标志" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="redo_flag" align="center" sortable title="复查标志" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="redo_result" sortable title="复查前结果" width="80" show-overflow></vxe-table-column>
                                            <vxe-table-column field="orig_result_num" sortable title="原始数值结果" width="150" show-overflow></vxe-table-column>
                                            <vxe-table-column field="orig_result_str" sortable title="原始文本结果" width="150" show-overflow></vxe-table-column>
                                            <vxe-table-column field="modify_flag" sortable title="修改标志" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="first_dt" align="center" sortable title="第一次填入时间" width="120" show-overflow></vxe-table-column>
                                            <vxe-table-column field="last_dt" align="center" sortable title="最后修改时间" width="120" show-overflow></vxe-table-column>
                                            <vxe-table-column field="last_user" align="center" sortable title="最后修改人" width="80" show-overflow></vxe-table-column>
                                            <vxe-table-column field="rptunitid" sortable title="报告单元" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="germflag" align="center" sortable title="细菌标志" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="orig_result_flag" align="center" sortable title="原始结果标志" width="60" show-overflow></vxe-table-column>
                                            <template v-slot:fix>
                                                <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">合计: {{result_amount}}</span>
                                                    <div style="clear:both"></div>
                                                </div>
                                            </template>
                                        </vxe-table>
                                    </div>
                                    <div class="middle-tab-bottom">
                                        <vxe-table :data.sync="resultMedData" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border header-align="center" height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" :key="ymkey">
                                            <vxe-table-column field="medname" sortable title="抗生素" width="220" show-overflow></vxe-table-column>
                                            <vxe-table-column field="medresult" sortable title="药敏结果" header-align="center" align="center" width="60" show-overflow>
                                                <template v-slot="{ row }">
                                                    <div :style="{
                            background: row.cp_resultbackgroundcolor,
                            color: row.cp_resultcolor
                          }" style="padding:0px 10px">
                                                        {{ row.medresult }}
                                                    </div>
                                                </template>
                                            </vxe-table-column>
                                            <vxe-table-column field="rad" sortable title="Rad" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="mic" sortable title="Mic" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result_flag" align="center" sortable title="标志" width="60" show-overflow></vxe-table-column>
                                            <vxe-table-column field="result6" sortable title="参考范围" width="120" show-overflow></vxe-table-column>
                                            <vxe-table-column field="expertresult" sortable title="专家值" width="100" show-overflow></vxe-table-column>
                                            <vxe-table-column field="medgroup" align="center" sortable title="分组" width="80" show-overflow></vxe-table-column>
                                            <template v-slot:fix>
                                                <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">合计:
                                                        {{ymresultitem_amount}}</span>
                                                    <div style="clear:both"></div>
                                                </div>
                                            </template>
                                        </vxe-table>
                                    </div>
                                </div>
                                <div v-if="!bIsYm" class="right-inser">
                                    <vxe-table :data.sync="resultData" :loading="bResultLoading" header-align="center" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" :key="rptitemkey">
                                        <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="220" show-overflow> <template v-slot="{ row }">
                                                <div v-if="row.alertflag == '1'" style="background:red;padding:0px 10px">
                                                    {{ row.rpt_itemname }}
                                                </div>
                                                <div v-else style="padding:0px 10px">
                                                    {{ row.rpt_itemname }}
                                                </div>
                                            </template></vxe-table-column>
                                        <vxe-table-column field="result_str" sortable title="检测结果" width="80" show-overflow> <template v-slot="{ row }">
                                                <div :style="{
                            background: row.cp_resultbackgroundcolor,
                            color: row.cp_resultcolor
                          }" style="padding:0px 10px">
                                                    {{ row.result_str }}
                                                </div>
                                            </template></vxe-table-column>
                                        <vxe-table-column field="result_unit" sortable title="单位" width="70" show-overflow></vxe-table-column>
                                        <vxe-table-column field="result_ref" sortable title="参考值" width="100" show-overflow></vxe-table-column>
                                        <vxe-table-column field="result1" :title="result1text" width="70px" v-if="result1 == 1"></vxe-table-column>
                                        <vxe-table-column field="result2" :title="result2text" width="70px" v-if="result2 == 1"></vxe-table-column>
                                        <vxe-table-column field="result3" :title="result3text" width="70px" v-if="result3 == 1"></vxe-table-column>
                                        <vxe-table-column field="result_txt" sortable title="大文本结果" width="130" show-overflow></vxe-table-column>
                                        <vxe-table-column field="instrid" sortable title="检验仪器" width="100" show-overflow></vxe-table-column>
                                        <vxe-table-column field="interno" sortable title="通道号" width="100" show-overflow></vxe-table-column>
                                        <vxe-table-column field="alertflag" align="center" sortable title="危急标志" width="60" show-overflow></vxe-table-column>
                                        <vxe-table-column field="result_flag" align="center" sortable title="结果标志" width="60" show-overflow></vxe-table-column>
                                        <vxe-table-column field="redo_flag" align="center" sortable title="复查标志" width="60" show-overflow></vxe-table-column>
                                        <vxe-table-column field="redo_result" sortable title="复查前结果" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="orig_result_num" sortable title="原始数值结果" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="orig_result_str" sortable title="原始文本结果" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="modify_flag" align="center" sortable title="修改标志" width="60" show-overflow></vxe-table-column>
                                        <vxe-table-column field="first_dt" align="center" ortable title="第一次填入时间" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="last_dt" align="center" sortable title="最后修改时间" width="120" show-overflow></vxe-table-column>
                                        <vxe-table-column field="last_user" align="center" sortable title="最后修改人" width="80" show-overflow></vxe-table-column>
                                        <vxe-table-column field="rptunitid" sortable title="报告单元" width="150" show-overflow></vxe-table-column>
                                        <vxe-table-column field="germflag" align="center" sortable title="细菌标志" width="60" show-overflow></vxe-table-column>
                                        <vxe-table-column field="orig_result_flag" align="center" sortable title="原始结果标志" width="160" show-overflow></vxe-table-column>
                                        <template v-slot:fix>
                                            <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">合计: {{result_amount}}</span>
                                                <div style="clear:both"></div>
                                            </div>
                                        </template>
                                    </vxe-table>
                                </div>
                            </template>
                        </rm-layout-right>
                    </el-tab-pane>
                    <el-tab-pane label="申请单" name="reqTab">
                        <div style="height:100%">
                            <vxe-table :data.sync="reqData" :loading="bReqLoading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" header-align="center" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="reqTable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" :key="reqkey">
                                <vxe-table-column field="report_dt" title="报告时间" align="center" width="120px"></vxe-table-column>
                                <vxe-table-column field="req_groupna" sortable title="分单类别" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="barcode" sortable title="条形码" align="center" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="emer_flag" align="center" sortable title="急" :formatter="['formatSelect', emer_flagOptions]" width="25" show-overflow>
                                    <template v-slot="{ row}">
                                        <div v-if="row.emer_flag == '1'">
                                            <font color="red" style="font-weight:600;font-size:14px;">急</font>
                                        </div>
                                        <div v-else>
                                        </div>
                                    </template>
                                </vxe-table-column>
                                <vxe-table-column field="sample_items" sortable title="申请项目(描述)" width="350" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_statname" align="center" sortable title="状态" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="create_dt" align="center" sortable title="创建时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="recieve_dt" title="接收时间" width="120px" align="center"></vxe-table-column>
                                <vxe-table-column field="recieve_username" title="接收人" width="70px" align="center"></vxe-table-column>
                                <vxe-table-column field="test_dt" title="上机时间" align="center" width="120px"></vxe-table-column>
                                <vxe-table-column field="test_username" title="上机人" width="70px" align="center"></vxe-table-column>
                                <vxe-table-column field="req_deptname" sortable title="申请科室" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_doc" sortable title="申请医生" width="80" align="center" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_bedno" align="center" sortable title="床号" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="specimen_name" align="center" sortable title="标本类型" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_sexname" align="center" sortable title="性别" width="50" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_agestr" align="center" sortable title="年龄" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="base_amount" align="right" sortable title="应收金额" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="create_username" align="center" sortable title="创建人" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="print_dt" align="center" sortable title="打印/执行时间" width="130" show-overflow></vxe-table-column>
                                <vxe-table-column field="print_username" align="center" sortable title="打印/执行人" width="110" show-overflow></vxe-table-column>
                                <vxe-table-column field="print_count" align="center" sortable title="打印次数" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="sampled_dt" align="center" sortable title="采样时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="sampled_username" align="center" sortable title="采样人" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_dt" align="center" sortable title="申请时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="release_dt" align="center" sortable title="发布时间" width="140" show-overflow></vxe-table-column>
                                <vxe-table-column field="prereport_dt" align="center" sortable title="预出报告时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="prereport_comm" sortable title="报告领取说明" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_diag" sortable title="临床诊断" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_id" sortable title="病人ID" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="inp_date" align="center" sortable title="入院日期" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="send_dt" align="center" sortable title="送出时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="send_username" sortable title="送出人" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="charge_dt" align="center" sortable title="计价时间" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="charge_username" sortable title="计价人" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="amount" align="right" sortable title="实收金额" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="sampled_chkusername" title="采样核对者" align="center" width="100px"></vxe-table-column>
                                <!-- <vxe-table-column field="reqsource" sortable title="申请单来源" :formatter="['formatSelect', reqsourceOptions]" width="150" show-overflow></vxe-table-column> -->
                                <vxe-table-column field="pat_no" sortable title="病历号" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="recieve1_dt" title="工作组接收时间" width="100px"></vxe-table-column>
                                <vxe-table-column field="recieve1_username" title="工作组接收用户" width="100px"></vxe-table-column>
                                <vxe-table-column field="pat_typename" title="病人类型" width="100px"></vxe-table-column>
                                <vxe-table-column field="cancel_dt" title="作废时间" width="120px"></vxe-table-column>
                                <vxe-table-column field="cancel_username" title="作废用户" width="100px"></vxe-table-column>
                                <vxe-table-column field="chargeex_flag" sortable title="计价标志" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="alter_flag" sortable title="报警" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="saleman" sortable title="销售人" align="center" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_cardno" sortable title="就诊卡号" width="120" show-overflow></vxe-table-column>
                                <vxe-table-column field="report_username" title="检验医生姓名" align="center" width="80px"></vxe-table-column>
                                <vxe-table-column field="rechk_username" title="核对医生姓名" align="center" width="80px"></vxe-table-column>
                                <vxe-table-column field="req_comm" sortable title="医生备注" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="reject_dt" title="退回时间" align="center" width="120px"></vxe-table-column>
                                <vxe-table-column field="reject_username" title="退回用户" align="center" width="80px"></vxe-table-column>
                                <vxe-table-column field="reject_reason" title="退回原因" width="150px"></vxe-table-column>
                                <vxe-table-column field="reject_count" title="退回次数" align="center" width="60px"></vxe-table-column>
                                <vxe-table-column field="pat_birth" sortable title="生日" align="center" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_agestr" sortable title="年龄岁数" align="center" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="inp_id" sortable title="住院标志" align="center" width="80" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_diag_icd" sortable title="诊断标准代码" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_address" sortable title="地址" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_nation" sortable title="国籍" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_idcardno" sortable title="身份证号" align="center" width="130" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_phone" sortable title="联系电话" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="charge_typeno" sortable title="费别代码" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="perform_dept" sortable title="执行科室" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_ward" sortable title="病区代码" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="original_reqno" sortable title="原始单号" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="secrecy" sortable title="加密" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="other_stat" sortable title="其它状态" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="specimen_code" sortable title="标本类型代码" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="sample_detail" sortable title="标准备注说明" width="150" show-overflow></vxe-table-column>
                                <vxe-table-column field="req_reason" sortable title="送检目的" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="pat_height" sortable title="身高(CM)" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="weight" sortable title="体重(KG)" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="abo_bldtype" sortable title="ABO血型" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="rh_bldtype" sortable title="RH血型" width="100" show-overflow></vxe-table-column>
                                <vxe-table-column field="discard_username" sortable title="遗弃人" align="center" width="70" show-overflow></vxe-table-column>
                                <vxe-table-column field="discard_dt" sortable title="遗弃时间" align="center" width="120" show-overflow></vxe-table-column>
                                <template v-slot:fix>
                                    <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span style="color:red;margin-left:10px;float:right;">合计: {{req_amount}}</span>
                                        <div style="clear:both"></div>
                                    </div>
                                </template>
                            </vxe-table>
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </div>
        </div>
        <!--多选弹窗--->
        <el-dialog width="830px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="Closedialog"></rm-SqlMultiple>
        </el-dialog>
        <!-- 批量打印提示-->
        <el-dialog title="提示" :visible.sync="bPrintDlg" width="30%" v-el-drag-dialog :close-on-click-modal="false">
            <div style="font-size:18px;font-weight:800;">{{ printmsg }}</div>
        </el-dialog>
    </div>
</template>

<script>
import XE from "xe-utils"; //引入工具类
export default {
    name: "LIS422",
    data() {
        return {
            //************ 变量声明及初始化模块列表*/
            //**【TOP】查询条件                                                 */
            //**【CENTER_TAB1_LEFT】病区科室列表    */
            //**【CENTER_TAB1_CENTER】报告单            */
            //**【CENTER_TAB1_RIGHT】报告项目           */
            //**【CENTER_TAB2_CENTER】申请单            */
            //**【多选组件】                                                          */
            //**【其他】                                                                    */
            //************** *********************/

            //*【TOP】查询条件 */
            searchObj: {
                //ROW_1
                sample_startdt: this.$pub.InitDateTime2(0).datefrom, //起始日期
                sample_enddt: this.$pub.InitDateTime2(0).dateto, //结束日期
                pat_no: "", //病历号
                barcode: "", //条码号
                rpt_itemcode: "", //报告项目
                specimen_code: "", //标本类型
                //ROW_2
                pat_typecode: "3", //病人类型
                pat_name: "", //病人姓名,
                pat_name_mh: "", //病人姓名_模糊
                labgroup: "", //检验组别
                rptunitgroupid: "", //单元组合
                report_user: "", //检验者
                //ROW_3
                labdeptcode: "", //检验科室
                isprint: "0", //打印状态
                chkmode: "0", //科室/病区模式
                wdcombno: "", //病区组合
                rechk_user: "", //审核者
            },
            labdeptOption: [],
            rptunitOption: [],
            pattypeOption: [],
            labgroupOption: [],
            rptunitGroupOption: [],
            specimenOption: [],
            resultcombOption: [],
            //**【CENTER_TAB1_LEFT】病区科室列表 */
            listData: [], //初次报告数据
            listKey: 0,
            bListLoading: false, //初次查询Loading
            //**【CENTER_TAB1_CENTER】报告单*/
            allData: [],
            rptData: [],
            rptkey: 0,
            rpt_amount: 0,
            bRptLoading: false,
            //**【CENTER_TAB1_RIGHT】报告项目 */
            resultData: [],
            ymkey: 0,
            rptitemkey: 0,
            ymitemkey: 0,
            result_amount: 0,
            bIsYm: false, //是否显示药敏
            bResultLoading: false,
            result1text: "",
            result2text: "",
            result3text: "",
            result1: "",
            result2: "",
            result3: "",
            //**报告单打印 */
            printReportid: "",
            selectall: "", //全选
            macaddress: "", //Mac地址
            rechkflag: "", //审核标志
            printmsg: "", //打印信息
            bPrintDlg: false,
            //**【CENTER_TAB2_CENTER】申请单 */
            reqData: [],
            bReqLoading: false,
            reqkey: 0,
            req_amount: 0,
            emer_flagOptions: [
                { label: "", value: "0" },
                { label: "急", value: "1" },
            ],
            reqsourceOptions: [
                { label: "读取外部系统申请单", value: "0" },
                { label: "LIS门诊采血生成", value: "1" },
                { label: "病区护士站生成", value: "3" },
                { label: "住院医生站生成", value: "4" },
                { label: "标本拆分之后的标本", value: "5" },
                { label: "为院感系统生产", value: "6" },
                { label: "输入病历号开窗选取项目后生成", value: "21" },
                { label: "Lis系统登记生成", value: "22" },
                { label: "通过检验中心登记", value: "23" },
                { label: "外院标本", value: "24" },
                { label: "POCT生成的申请单", value: "25" },
                { label: "报告处理界面录入的申请", value: "26" },
                { label: "住院医生站输血申请", value: "41" },
                { label: "输血申请附带的检验申请", value: "42" },
            ],
            txtoperatorOptions: [
                {
                    value: "In",
                    label: "等于",
                },
                {
                    value: "NotIn",
                    label: "不等于",
                },
            ],
            //**【多选组件】*/
            option1: [],
            option2: [],
            fieldname: "",
            multichktitle: "", //多选标题
            dialogMultipleVisible: false, //多选弹框
            //**【其他】*/
            activeTabName: "rptTab", //默认tab页
        };
    },
    created() {
        this.BtnClear();
    },
    mounted() {
        let LIS422Cache = localStorage.getItem("LIS422Cache");
        let tempOption = JSON.parse(LIS422Cache);
        if (LIS422Cache) {
            this.searchObj.pat_typecode = tempOption.pat_typecode;
            this.searchObj.labdeptcode = tempOption.labdeptcode;
            this.searchObj.isprint = tempOption.isprint;
            this.searchObj.chkmode = tempOption.chkmode;
        }
        this.$nextTick(() => {
            this.initOption();
        });
    },
    methods: {
        //? ****************初始化获取数据******************//
        //缓存
        LoadSave() {
            let jsondata = {
                pat_typecode: this.searchObj.pat_typecode,
                labdeptcode: this.searchObj.labdeptcode,
                isprint: this.searchObj.isprint,
                chkmode: this.searchObj.chkmode,
            };
            let modListJson = JSON.stringify(jsondata);
            localStorage.setItem("LIS422Cache", modListJson);
            this.$nextTick(() => {
                // this.initOption();
            });
        },
        //初始化组件getOption
        async initOption() {
            if (typeof jsObj != "undefined") {
                var computeInfo = jsObj.GetComputeInfo();
                var arr = computeInfo.split("\r");
                if (arr.length == 3) {
                    this.macaddress = arr[0];
                }
            } else {
                this.macaddress = "Default";
            }
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS422",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                });
                this.labdeptOption = res.labdeptOption;
                if (this.labdeptOption.length > 0) this.searchObj.labdeptcode = this.labdeptOption[0].data;
                this.rptunitOption = res.rptunitOption;
                this.pattypeOption = res.pattypeOption;
                this.specimenOption = res.specimenOption;
                this.labgroupOption = res.labgroupOption;
                this.resultcombOption = res.resultcombOption;
                this.rptunitGroupOption = res.rptunitGroupOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        //Tab页点击事件
        HandleClick(tab) {
            if (tab.label == "报告单") {
                this.listKey++;
            } else if (tab.label == "申请单") {
                this.reqkey++;
                console.log("🐘🐘🐘🐘🐘 —— this.reqkey", this.reqkey);
                let row = this.$refs.rptTable.getCurrentRow();
                if (XE.isNull(row)) {
                    this.$message.error("请您先选择一条报告单数据！");
                    return false;
                } else {
                    this.bReqLoading = true;
                    this.req_amount = 0;
                    //获取申请单数据
                    this.$tool
                        .request({
                            url: "LIS/LIS4/LIS410",
                            method: "post",
                            data: {
                                action: "get_reqmaster",
                                pat_id: row.pat_id,
                            },
                        })
                        .then((res) => {
                            this.bReqLoading = false;
                            if (res == "0") {
                                this.reqData = [];
                                this.$message.error("无数据返回，原因:所选数据病人ID为空。");
                            } else {
                                this.reqData = res.Data;
                                this.req_amount = this.reqData.length;
                            }
                        })
                        .catch((e) => {
                            this.$message.error(e);
                            this.bReqLoading = true;
                        });
                }
            }
        },
        //? ******************功能************************/
        //查询
        BtnQuery() {
            this.activeTabName = "rptTab";
            this.ClearData();
            this.bRptLoading = true;
            this.bListLoading = true;
            this.bResultLoading = true;
            this.bIsYm = false;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS422",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "querymodeNrpt",
                        ...this.searchObj,
                    },
                })
                .then((res) => {
                    this.listData = res.listdata;
                    if (res.data) {
                        if (res.data.length > 0) {
                            if (res.data.length > 5000) {
                                //未选择病区/科室时，只显示5000行好了
                                this.rptData = res.data.slice(0, 5000);
                            } else {
                                this.rptData = res.data;
                            }
                            this.rpt_amount = res.cnt;
                            this.$refs.rptTable.setCurrentRow(this.rptData[0]);
                            this.BtnQueryResult(this.rptData[0]);
                            this.rechkflag = this.rptData[0].rechkflag;
                            this.printReportid = this.rptData[0].reportid;
                            this.allData = XE.clone(res.data, true);
                        }
                    }
                    this.bRptLoading = false;
                    this.bListLoading = false;
                    this.bResultLoading = false;
                })
                .catch((e) => {
                    console.log(e);
                    this.bRptLoading = false;
                    this.bListLoading = false;
                    this.bResultLoading = false;
                });
        },
        //查询结果
        BtnQueryResult(row) {
            this.bResultLoading = true;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS422",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "get_labresult",
                        reportid: row.reportid,
                        rptunitid: row.rptunitid,
                        macaddress: this.macaddress,
                    },
                })
                .then((res) => {
                    if (res.rtn.length > 1) {
                        //药敏
                        this.bIsYm = true;
                        this.resultData = res.rtn[0];
                        this.resultMedData = res.rtn[1];
                        this.result_amount = this.resultData.length;
                        this.ymresultitem_amount = this.resultMedData.length;
                    } else {
                        this.bIsYm = false;
                        this.resultData = res.rtn[0];
                        this.result1text = res.result1text;
                        this.result2text = res.result2text;
                        this.result3text = res.result3text;
                        this.result1 = res.result1;
                        this.result2 = res.result2;
                        this.result3 = res.result3;
                        this.result_amount = this.resultData.length;
                    }
                    this.bResultLoading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        //改变查询模式
        ChangeNSaveChache() {
            this.listKey++;
            this.LoadSave();
            this.ClearData();
        },
        //清除
        BtnClear() {
            this.ClearData();
            this.searchObj = {
                //ROW_1
                sample_startdt: this.$pub.InitDateTime2(0).datefrom, //起始日期
                sample_enddt: this.$pub.InitDateTime2(0).dateto, //结束日期
                pat_no: "", //病历号
                barcode: "", //条码号
                rpt_itemcode: "", //报告项目
                specimen_code: "", //标本类型
                //ROW_2
                pat_typecode: "3", //病人类型
                pat_name: "", //病人姓名,
                pat_name_mh: "", //病人姓名_模糊
                labgroup: "", //检验组别
                rptunitgroupid: "", //单元组合
                report_user: "", //检验者
                //ROW_3
                labdeptcode: "", //检验科室
                isprint: "0", //打印状态
                chkmode: "0", //科室/病区模式
                wdcombno: "", //病区组合
                rechk_user: "", //审核者
            };
        },

        //清除表格数据
        //用于BtnClear 和改变查询条件清空表格
        ClearData() {
            this.selectall = false;
            this.bListLoading = false;
            this.bRptLoading = false;
            this.listData = [];
            this.rptData = [];
            this.resultData = [];
            this.resultMedData = [];
            this.printReportid = "";
            this.rechkflag = "";
            this.rpt_amount = 0;
            this.result_amount = 0;
            this.ymresultitem_amount = 0;
            this.req_amount = 0;
            this.printReportid = "";
        },
        //打印全选
        ChkAll(e) {
            if (this.rptData != null && this.rptData.length > 0) {
                this.rptData.forEach((item) => {
                    item.cp_selection = this.selectall == true ? "1" : "0";
                });
            }
        },
        //查阅病历_预先判断
        BtnQueryPatcase() {
            if (!this.printReportid) return false;
            this.GetPatcase(this.printReportid);
        },
        //查阅病历_查询
        GetPatcase(reportid) {
            this.$pub.getPatcase(this, reportid, 3);
        },
        //打印
        // 合并打印按钮 有勾选默认打印勾选 无勾选打印选中行报告
        //打印选择 勾选/选中行
        BtnPrint() {
            let printData = this.rptData.filter((item) => {
                return item.cp_selection == "1";
            });
            if (!(printData.length > 0)) {
                this.BtnCurrentPrint();
            } else {
                this.BtnBatchPrint();
            }
        },
        //打印_选中打印
        BtnCurrentPrint() {
            if (this.printReportid == "") {
                this.$message("请先选择一份报告进行打印!");
                return false;
            } else if (this.rechkflag != "9") {
                this.$message("当前报告未审核，不可打印!");
                return false;
            } else if (this.printReportid != "" && this.rechkflag == "9") {
                this.printmsg = "正在打印，共1份报告";
                this.bPrintDlg = true;
                this.$pub.printreport(this, this.printReportid, "1", "", "1", "1");
                setTimeout(() => {
                    this.bPrintDlg = false;
                }, 2000);
            }
        },
        // 打印_勾选打印
        BtnBatchPrint() {
            let printData = this.rptData.filter((item) => {
                return item.cp_selection == "1";
            });
            let len = printData.length;
            if (len > 0) {
                let name = [];
                let reportids = [];
                printData.forEach((item) => {
                    //遍历是否有不一样的的姓名的患者打印报告，有则提醒
                    if (name.indexOf(item.pat_name) > -1) {
                        //throw Error();
                    } else {
                        name.push(item.pat_name);
                    }
                    reportids.push(item.reportid);
                });
                if (name.length > 1) {
                    //有至少两个人的报告
                    this.$confirm("当前选中多个病人的报告单，你确定要打印吗？", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                        .then(() => {
                            this.PrintReport(len, reportids);
                        })
                        .catch((e) => {});
                } else {
                    //只有一个人的报告
                    this.PrintReport(len, reportids);
                }
            }
        },
        // 打印_勾选打印_循环打印
        PrintReport(len, reportids) {
            this.printmsg = "正在打印，共" + len + "份报告";
            this.bPrintDlg = true;
            // this.rptData.forEach((item) => {
            //     if (item.cp_selection == "1") {
            //         // if (this.autoprintuselisrpt == "1") {
            //         //报告使用LIS内部报告样式
            //         this.$pub.printreport(this, item.reportid, "1", "", "1");
            //         // } else {
            //         //     this.$pub.printreport(this, item.reportid, "1", "", "2");
            //         // }
            //         let k = Number(item.print_count);
            //         item.print_count = k + 1;
            //     }
            // });
            //按页面顺序打印
            let printdata = this.$refs.rptTable.afterFullData.filter((item) => reportids.indexOf(item.reportid) > -1);
            setTimeout(() => {
                this.PrintLoopFun(this, printdata, 0);
            }, 100);

            setTimeout(() => {
                this.bPrintDlg = false;
            }, 2000);
        }, 
        //按页面顺序打印
        PrintLoopFun(that, datas, printindex) {
            console.log(datas, printindex);
            that.PrintFun(that, datas, printindex).finally((e) => {
                datas[printindex].print_count = Number(datas[printindex].print_count) + 1;
                printindex++;
                if (printindex < datas.length) {
                    setTimeout(() => {
                        that.PrintLoopFun(that, datas, printindex);
                    }, 100);
                }
                // this.$pub.Log("PrintFun - end");
            });
        }, 
        // 注意打印顺序
        async PrintFun(that, datas, printindex) {
            that.$pub.printreport(that, datas[printindex].reportid, "1", "", "1");
        },
        // 勾选点击提示
        handleCheckedPrintChange(row, rowIndex) {
            //控制单选状态
            if (row.cp_selection != "0") {
                if (row.notserviceprint == "1") {
                    this.$alert("当前报告不可在服务台打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (row.rechkflag != 9) {
                    //9已审核
                    this.$alert("当前报告未审核，不可打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (row.prereport == "1") {
                    this.$alert("当前报告为初步报告，只可查询，不可打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (["1", "2", "8"].includes(row.unprint_flag)) {
                    if (row.unprint_flag == "1") {
                        this.$confirm("当前报告禁止自助打印，" + row.unprint_reason + "，打印未通过，你是否确定要打印？", "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            type: "warning",
                        })
                            .then(() => {
                                this.$nextTick(() => {
                                    row.cp_selection = "1";
                                });
                            })
                            .catch((e) => {
                                this.$nextTick(() => {
                                    row.cp_selection = "0";
                                });
                            });
                    } else if (["8"].includes(row.unprint_flag)) {
                        let msg = "当前报告禁止在服务台打印！";
                        if (row.unprint_flag == "8") {
                            msg = "当前报告需要单独授权才能打印，请到指定地点或用户处打印！";
                        }
                        this.$alert(msg, "提示", {
                            confirmButtonText: "确定",
                            callback: (action) => {
                                this.$nextTick(() => {
                                    row.cp_selection = "0";
                                });
                            },
                        });
                    }
                } else {
                    this.$nextTick(() => {
                        row.cp_selection == "0" ? "1" : "0";
                    });
                }
            }
        },
        //预览
        BtnPreView() {
            if (this.printReportid == "") {
                this.$message("请先选择一份报告进行预览!");
                return false;
            } else if (this.rechkflag != "9") {
                this.$message("当前报告未审核，不允许预览!");
                return false;
            } else if (this.printReportid != "" && this.rechkflag == "9") {
                this.$pub.printreport(this, this.printReportid, "2", "", "1", "1");
            }
        },
        //关闭按钮
        BtnExc() {
            let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "LIS422");
            this.$parent.$refs.itemtags.tagsList.splice(index, 1);
            this.$router.go(-1);
        },
        //焦点聚焦
        Focus(event) {
            event.currentTarget.select();
        },
        //? ******************currentchange*****************/
        //病区科室list行改变事件
        listCurrentChange({ row }) {
            this.bRptLoading = true;
            if (row.req_wardno != "all") {
                let rest = [];
                if (this.searchObj.chkmode == "0") {
                    rest = this.allData.filter((e) => e.req_wardno == row.req_wardno);
                } else {
                    rest = this.allData.filter((e) => e.req_deptno == row.req_deptno);
                }
                if (rest.length > 0) {
                    this.rptData = rest;
                }
                setTimeout(() => {
                    this.$refs.rptTable.setCurrentRow(this.rptData[0]);
                    this.BtnQueryResult(this.rptData[0]);
                }, 50);
            }
            this.rpt_amount = this.rptData.length;
            this.bRptLoading = false;
        },
        //报告单行改变事件
        rptCurrentChange({ row, rowIndex }, e) {
            //按住shift再单击一行，可以多选这些行
            if (e.shiftKey) {
                let data = this.$refs.rptTable.afterFullData; //要考虑到列头点击排序的问题
                var oId = -1;
                var nId = -1;
                for (var i = 0; i < data.length; i++) {
                    if (data[i].reportid.indexOf(this.printReportid) > -1) {
                        oId = i;
                    }
                    if (data[i].reportid.indexOf(row.reportid) > -1) {
                        nId = i;
                    }
                }
                if (oId > -1 && nId > -1) {
                    let min = oId;
                    let max = nId;
                    if (nId < oId) {
                        min = nId;
                        max = oId;
                    }
                    for (let i = min; i <= max; i++) {
                        if (max >= i) {
                            data[i].cp_selection = "1"; //在选中区域内循环赋值
                        }
                    }
                }
            }
            this.printReportid = row.reportid;
            this.rechkflag = row.rechkflag;
            this.exportna = row.reportid + "-" + row.pat_name;
            this.BtnQueryResult(row);
        },
        //? ******************组件************************/
        //多选组件 - 选择
        popMultipleChk(e, fieldname, option, title) {
            let temp = XE.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.dlgTitle = title;
            this.dialogMultipleVisible = true;
        },
        //多选组件 - 关闭
        Closedialog(value, name) {
            if (value != "close") {
                var narr = name.split(".");
                this[narr[0]][narr[1]] = value;
            }
            this.dialogMultipleVisible = false;
        },
        //? ******************CLASS************************/
        //报告单ROW_CLASS
        rptRowName({ row }) {
            if (this.cellreportid == row.reportid) {
                // return "rm-red";
            }
            if (row.rechk_dt != "" && row.rechk_dt != " " && row.rechk_dt != null) {
                if (XE.toNumber(row.print_count) > 0) {
                    return "rm-gray"; //审核过打印的
                } else {
                    return "noPrint"; //没打印的
                }
            }
        },
        //报告单CELL_CLASS
        rptCellName({ row, column }) {
            if (column.property == "alter_flag") {
                if (row.alter_flag == "1" || row.alter_flag == "2") {
                    return "colred";
                }
            } else if (column.property == "redo_flag") {
                if (row.redo_flag == "2" || row.redo_flag == "3") {
                    return "colgreen";
                }
            } else if (column.property == "pat_name" || column.property == "pat_no") {
                // 添加链接查询颜色
                return "col-blue";
            } else if (column.property == "unprint_reason") {
                return "col-red";
            }
        },
    },
    //快捷键 暂时只有查询界面用几个吧 等统一使用用了再补充
    beforeRouteEnter(to, from, next) {
        next((vm) => {
            let that = vm;
            let altArr = [];
            document.onkeydown = function (e) {
                let key = window.event.keyCode;
                //*组合按键
                if (altArr.length > 0) {
                    //65到90 a到z（A到Z）
                    //*Alt + C 清除
                    if (key == 67) {
                        that.BtnClear();
                    }
                    //*Alt + E 退出
                    if (key == 69) {
                        that.BtnExc();
                    }
                } else {
                    if (key == 119) {
                        //F8
                        that.BtnQuery();
                    } else if (key == 120) {
                        //F9
                    } else if (key == 18) {
                        //按下了alt
                        altArr.push(key);
                    }
                }
            };
            document.onkeyup = function (e) {
                let key = window.event.keyCode;
                if (key == 18) {
                    altArr = [];
                }
            };
        });
    },
};
</script>

<style scoped>
::v-deep .el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
::v-deep .vxe-table--header .vxe-header--column {
    border-right: 1px solid #cccccc;
    border-bottom: 1px solid #ccc;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
.pagetop {
    left: 0;
    right: 0;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}
.pagecenter {
    position: absolute;
    top: 135px;
    bottom: 0px;
    overflow: auto;
    width: 100%;
    left: 0px;
}
.middle_center {
    position: absolute;
    height: 100%;
    right: 0px;
    left: 0px;
    overflow: auto;
}
.middle-right {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 570px;
    right: 0px;
}
table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table tr td:nth-child(1) {
    width: 80px;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 0;
}
::v-deep .el-textarea__inner {
    padding: 0px 5px;
}
::v-deep .noPrint {
    background-color: #c0ffc0;
}
.middle-tab-top {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 200px;
}
.middle-tab-bottom {
    position: absolute;
    top: 203px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: auto;
    width: 100%;
    right: 0px;
}
</style>